package org.huangjiahui.rpc.hook;

import org.huangjiahui.rpc.factory.ThreadPoolFactory;
import org.huangjiahui.rpc.util.NacosUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author huangjiahui
 */
public class ShutdownHook {
    private static final Logger logger = LoggerFactory.getLogger(ShutdownHook.class);

    private static final ShutdownHook shutdownHood = new ShutdownHook();

    public static ShutdownHook getShutdownHood(){return shutdownHood;}

    public void addClearAllHook(){
        logger.info("关闭后将自动注销所有服务");
        Runtime.getRuntime().addShutdownHook(new Thread(()->{
            NacosUtil.clearRegistry();
            ThreadPoolFactory.shutDownAll();
        }));
    }
}
